<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Lynn的商品管理系统</title>
    <script src="./libs/jquery-3.4.1.min.js"></script>
    <link rel="stylesheet" href="./libs/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="./css/index.css">

    <script src="./libs/bootstrap/js/bootstrap.min.js"></script>

</head>

<body>
    <nav class="navbar navbar-inverse">
        <div class="container">
            <div class="navbar-header">
                <a class="navbar-brand" href="#">Lynn的商品管理系统</a>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li class="active"><a href="#">首页</a></li>
                    <li><a href="#">其他页面</a></li>
                </ul>
                <ul class="nav navbar-nav navbar-right">
                    <li class="show"><a href="./html/login.html">登录</a></li>
                    <li class="show"><a href="./html/register.html">注册</a></li class="unlogin">
                    <li class="hide"><a href="">欢迎<b></b></a></li class="login">
                    <li class="hide" id="out" ><a href="javascript:void(false)">退出</a></li>
                </ul>
            </div><!-- /.navbar-collapse -->
        </div><!-- /.container-fluid -->
    </nav>
    <div class="container">
        <button class="btn btn-sm btn-primary btn-add" data-toggle="modal" data-target="#addModal">添加商品</button>
        <table class="table table-bordered table-striped table-hover table-list">
            <thead>
                <tr>
                    <th>编号</th>
                    <th>商品名称</th>
                    <th>商品价格</th>
                    <th>商品数量</th>
                    <th>操作</th>
            </thead>
            <tbody class="tbody-list">
                <!-- //编辑状态 只需要在tr价格class类为edit -->
                <!-- <tr>
                    <td>1</td>
                    <td>
                        <span>AK47</span>
                        <input type="text">
                    </td>
                    <td>
                        <span>30</span>
                        <input type="text">
                    </td>
                    <td>
                        <span>100</span>
                        <input type="text">
                    </td>
                    <td>
                        <button class="btn btn-xs btn-info btn-edit">编辑</button>
                        <button class="btn btn-xs btn-danger btn-del">删除</button>
                        <button class="btn btn-xs btn-success btn-ok">确定</button>
                        <button class="btn btn-xs btn-warning btn-cancel">取消</button>
                    </td>
                </tr> -->
            </tbody>
        </table>
    </div>
    <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">添加商品</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal">
                        <div class="form-group">
                            <label for="inputName" class="col-sm-2 control-label">商品名称</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="inputName" placeholder="请输入商品名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputPrice" class="col-sm-2 control-label">商品价格</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="inputPrice" placeholder="请输入商品价格">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputNum" class="col-sm-2 control-label">商品数量</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="inputNum" placeholder="请输入商品数量">
                            </div>
                        </div>
                    </form>
                </div>
                <p id="info" class="text-center"></p>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="btn-add">添加</button>
                </div>
            </div>
        </div>
    </div>
    <script src="./js/utils.js"></script>
    <script>
        // console.log(utils.getCookie('loginState'))
        let btnAdd = document.getElementsByClassName('btn-add')[0]
        let loginState = utils.getCookie('loginState')
        let loginuser = utils.getCookie('username')
       //初始状态
        let onlog = document.querySelectorAll('.hide')
        let offlog = document.querySelectorAll('.show')
        let onname = document.querySelector('b')
        let logout = document.querySelector('#out')
        // console.log(logout)
        logout.onclick = function(e){
            e = e || window.event
            console.log(1)
            utils.setCookie('loginState','clear',{ path:'/',expires:-1 })
            window.location.reload()
        }
        // console.log(onname)
        // console.log(onlog)
        if(loginState === 'on'){
            offlog.forEach((item)=>{
                item.className = 'hide'
            })
            onlog.forEach((item)=>{
                item.className = 'show'
            })
            onname.innerText = loginuser
        }else{
            offlog.forEach((item)=>{
                item.className = 'show'
            })
            onlog.forEach((item)=>{
                item.className = 'hide'
                onname.innerText = null
            })
        }


        // btnAdd.onclick = () => {
        //     if (loginState === 'on') {
        //         console.log('OK')
        //     } else {
        //         console.log('请先登录')
        //     }
        // }
        // console.log(btnAdd)
    </script>
    <script src="./js/selecte.js"></script>
    <script src="./js/add.js"></script>
    <script src="./js/del.js"></script>
    <script src="./js/edit.js"></script>
</body>

</html>